import React from 'react';
import { createBrowserRouter, Navigate } from 'react-router-dom';
import { Layout } from 'antd';

// 企业官网页面
import {
  HomePage,
  ProductPage,
  ProductDetailPage,
  CasePage,
  CaseDetailPage,
  AboutPage,
} from '../pages/web';

// 后台管理页面
import {
  DashboardPage,
  ProductManagePage,
  CaseManagePage,
  SystemPage
} from '../pages/admin';

//公告页面
import LoginPage  from '../pages/LoginPage';
import NotFoundPage from '../pages/NotFoundPage';

// 布局组件
import WebLayout from '../layouts/WebLayout';
import AdminLayout from '../layouts/AdminLayout';
import AuthGuard from '../components/AuthGuard';

// 创建路由配置
export const router = createBrowserRouter([
  {
    path: '/',
    element: <WebLayout />,
    children: [
      {
        index: true,
        element: <HomePage />
      },
      {
        path: 'products',
        element: <ProductPage />
      },
      {
        path: 'products/:id',
        element: <ProductDetailPage />
      },
      {
        path: 'cases',
        element: <CasePage />
      },
      {
        path: 'cases/:id',
        element: <CaseDetailPage />
      },
      {
        path: 'about',
        element: <AboutPage />
      }
    ]
  },
  {
    path: '/cxggad',
    element: (
      <AuthGuard>
        <AdminLayout />
      </AuthGuard>
    ),
    children: [
      {
        index: true,
        element: <Navigate to="/cxggad/dashboard" replace />
      },
      {
        path: 'dashboard',
        element: <DashboardPage />
      },
      {
        path: 'products',
        element: <ProductManagePage />
      },
      {
        path: 'cases',
        element: <CaseManagePage />
      },

      {
        path: 'system',
        element: <SystemPage />
      }
    ]
  },
  {
    path: '/login',
    element: <LoginPage />
  },
  {
    path: '*',
    element: <NotFoundPage />
  }
]);

export default router;